define BUILD
@+QPEDIR=`cd $(QPEDIR); /bin/pwd`;\
outpath=`cd /home/jnussas/NDS/qtopia-free-2.2.0/qtopia; /bin/pwd`;\
if [ "$$QPEDIR" = "$$outpath" ]; then\
    $(MAKE) -C src $@;\
else \
    shadowdir=`echo $$PWD | perl -ne 's,'$$outpath','$$QPEDIR',;print'`;\
    if [ "$$shadowdir" != "$$PWD" ]; then\
	cd "$$shadowdir";\
	$(MAKE) -C src $@;\
    else\
	echo "ERROR: Trying to shadow hop but PWD is outside the Qtopia source tree.";\
	echo "       OUTPATH='$$outpath'";\
	echo "       QPEDIR='$$QPEDIR'";\
	echo "       PWD='$$PWD'";\
	exit 1;\
    fi;\
fi
endef

define CLEANINST
@+QPEDIR=`cd $(QPEDIR); /bin/pwd`;\
outpath=`cd /home/jnussas/NDS/qtopia-free-2.2.0/qtopia; /bin/pwd`;\
if [ "$$QPEDIR" = "$$outpath" ]; then\
     if [ -e "$(QPEDIR)/src/Makefile" ]; then\
				    prefix=`awk -F= '/^PREFIX/{print $$2}' $(QPEDIR)/src/Makefile`;\
					if [ -d "$$prefix" ]; then\
					    rm -rf "$$prefix";\
					fi;\
				    fi;\
				    if [ -e "$(QPEDIR)/src/qtopiadesktop/src/Makefile" ]; then\
					prefix=`awk -F= '/^DPREFIX/{print $$2}' $(QPEDIR)/src/qtopiadesktop/src/Makefile`;\
					if [ -d "$$prefix" ]; then\
					    rm -rf "$$prefix";\
					fi;\
				    fi;\
				    $(MAKE) install;\
else \
    shadowdir=`echo $$PWD | perl -ne 's,'$$outpath','$$QPEDIR',;print'`;\
    if [ "$$shadowdir" != "$$PWD" ]; then\
	cd "$$shadowdir";\
	 if [ -e "$(QPEDIR)/src/Makefile" ]; then\
				    prefix=`awk -F= '/^PREFIX/{print $$2}' $(QPEDIR)/src/Makefile`;\
					if [ -d "$$prefix" ]; then\
					    rm -rf "$$prefix";\
					fi;\
				    fi;\
				    if [ -e "$(QPEDIR)/src/qtopiadesktop/src/Makefile" ]; then\
					prefix=`awk -F= '/^DPREFIX/{print $$2}' $(QPEDIR)/src/qtopiadesktop/src/Makefile`;\
					if [ -d "$$prefix" ]; then\
					    rm -rf "$$prefix";\
					fi;\
				    fi;\
				    $(MAKE) install;\
    else\
	echo "ERROR: Trying to shadow hop but PWD is outside the Qtopia source tree.";\
	echo "       OUTPATH='$$outpath'";\
	echo "       QPEDIR='$$QPEDIR'";\
	echo "       PWD='$$PWD'";\
	exit 1;\
    fi;\
fi
endef

all:
	$(BUILD)
distclean:
	$(BUILD)
clean:
	$(BUILD)
install:
	$(BUILD)
install_target:
	$(BUILD)
uninstall:
	$(BUILD)
packages:
	$(BUILD)
lupdate:
	$(BUILD)
sdk:
	$(BUILD)
devsdk:
	$(BUILD)
remove_target:
	$(BUILD)
relink:
	$(BUILD)
first:
	$(BUILD)
qmake_all:
	$(BUILD)
uicables:
	$(BUILD)
mocables:
	$(BUILD)
uiclean:
	$(BUILD)
mocclean:
	$(BUILD)
lexclean:
	$(BUILD)
yaccclean:
	$(BUILD)
uninstall_subdirs:
	$(BUILD)
install_subdirs:
	$(BUILD)
FORCE:
	$(BUILD)
qmake:
	$(BUILD)
regenerate:
	$(BUILD)
cleaninstall:
	$(CLEANINST)
.PHONY: all distclean clean install install_target uninstall packages lupdate sdk devsdk remove_target relink first qmake_all uicables mocables uiclean mocclean lexclean yaccclean uninstall_subdirs install_subdirs FORCE qmake regenerate cleaninstall

